package js.web.center.utils;

import java.util.Properties;

import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;

import js.web.center.core.config.JsWebConfig;
import js.web.center.script.core.JsWebScriptEngineCore;
/**
 * 
 * @author dowell
 *
 */
public class JsWebVelocityUtils {
	private static Properties properties=null;
	public static VelocityEngine getVelocityEngine(){
		if(properties==null){
			properties=new Properties();
	        properties.setProperty(Velocity.ENCODING_DEFAULT, JsWebConfig.DEFAULT_CHAR_CODE);
	        properties.setProperty(Velocity.INPUT_ENCODING, JsWebConfig.DEFAULT_CHAR_CODE);
	        properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,JsWebConfig.rootPath+"/"+JsWebScriptEngineCore.basePath+JsWebConfig.templatePath);
	        properties.setProperty("runtime.log", JsWebConfig.rootPath+"/logs/template.log");
		}
		VelocityEngine velocityEngine = null;
		try {
			velocityEngine = new VelocityEngine(properties);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return velocityEngine;
	}
}
